package com.szc.demo01.controller;

import com.szc.demo01.controller.base.BaseController;
import com.szc.demo01.pojo.Authority;
import com.szc.demo01.pojo.Dept;
import com.szc.demo01.service.AuthorityService;
import com.szc.demo01.service.DeptService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * 主界面控制器
 */
@Controller
public class IndexController extends BaseController {

    @Resource
    DeptService deptService;

    @Resource
    AuthorityService authorityService;

    /**
     * 去登录页
     * @return
     */
    @GetMapping(value = {"/","/login"})
    public String toLogin(){
        return "login";
    }

    /**
     * 登出
     * @param httpSession
     * @return
     */
    @GetMapping("/loginOut")
    public String loginOut(HttpSession httpSession){
        httpSession.invalidate();
        return "redirect:/login";
    }

    /**
     * 去主页面
     * @return
     */
    @GetMapping("/main.html")
    public String mainPage(Model model){
        return "redirect:/to_showUser";
    }

    /**
     * 去注册界面
     * @return
     */
    @GetMapping("/registration.html")
    public String toRegistration(Model model){
        List<Dept> deptList = deptService.list();
        model.addAttribute("deptList",deptList);
        List<Authority> authorityList = authorityService.list();
        model.addAttribute("authorityList",authorityList);
        return "registration";
    }



}
